package com.qianwen.wallpaper;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;

import androidx.core.app.ActivityCompat;

/**
 * 主进程
 *
 * @author qianwen
 * @since 2021/7/24
 */
public class MainActivity extends Activity {
    private static final String[] PERMISSIONS = new String[]{
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.SET_WALLPAPER
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        for (String permission : PERMISSIONS) {
            if (ActivityCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(this, new String[]{permission}, 1);
            }
        }
        Intent intent = new Intent();
        intent.setClass(this, MyWallPaperService.class);
        intent.putExtra("type", "desktop");
        intent.setAction("com.qianwen.wallpaper.switch");
        startService(intent);
    }

    @Override
    protected void onResume() {
        super.onResume();
        finish();
    }
}